package com.hongxun.budget.utils;

import android.text.TextUtils;

import com.hongxun.entity.ImageUrl;
import com.hongxun.entity.LineName;
import com.hongxun.greenentity.tk.BEntryCriteriaEntity;
import com.hongxun.greenentity.tk.BMaterialEntity;
import com.hongxun.greenentity.tk.DPictureEntity;
import com.hongxun.net.Contants;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 数据转换工具类
 */

public class DataUtils {
    /**
     * 根据String转换为ImageUrl格式-方便查看大图
     *
     * @param datas
     * @return
     */
    public static List<ImageUrl> string2Image(List<String> datas) {
        List<ImageUrl> list = new ArrayList<>();
        for (String s : datas) {
            if (!s.equals(""))
                list.add(new ImageUrl(s, null));
        }
        return list;
    }

    /**
     * 根据String转换为ImageUrl格式-方便查看大图
     *
     * @param datas
     * @return
     */
    public static List<ImageUrl> dPicture2Image(List<DPictureEntity> datas) {
        List<ImageUrl> list = new ArrayList<>();
        for (DPictureEntity s : datas) {
            if (!TextUtils.isEmpty(s.getPAppaddress())) {
                if (new File(s.getPAppaddress()).exists()) {//判断图片是否本地存在
                    list.add(new ImageUrl(s.getPAppaddress(), null));
                } else {
                    list.add(new ImageUrl(Contants.baseUrl + Contants.showPic + s.getPServeraddress(), null));
                }
            }
        }
        return list;
    }

    /**
     * 准入条件转String
     *
     * @param entities
     * @return
     */
    public static List<String> entryCriteria2String(List<BEntryCriteriaEntity> entities) {
        List<String> list = new ArrayList<>();
        for (BEntryCriteriaEntity e : entities) {
            list.add(e.getECCriteria());
        }
        return list;
    }

    /**
     * 材料转String
     *
     * @param entities
     * @return
     */
    public static List<String> material2String(List<BMaterialEntity> entities) {
        List<String> list = new ArrayList<>();
        for (BMaterialEntity e : entities) {
            list.add(e.getMName());
        }
        return list;
    }

    /**
     * 材料转String
     *
     * @param entities
     * @return
     */
    public static List<String> lineName2String(List<LineName> entities) {
        List<String> list = new ArrayList<>();
        for (LineName e : entities) {
            list.add(e.getName());
        }
        return list;
    }

}
